//
// Created by xili on 2024/7/28 15:16.
// Go big or go home.
//
#include <unordered_map>

using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;

    TreeNode() : val(0), left(nullptr), right(nullptr) {}

    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}

    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

class Solution {
public:
    unordered_map<int, int> um;

    bool findTarget(TreeNode *root, int k) {
        if (!root) {
            return false;
        }
        if (um.count(k - root->val)) {
            return true;
        }
        um[root->val]++;
        return findTarget(root->left, k) || findTarget(root->right, k);
    }
};